﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Property_Info_Discussion : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.IsAuthenticated)
        {

            BindData();
        }
        else
        {
            Label1.Text = "Please sign in";
        }
    }

    void BindData()
    {
        SqlConnection cn = new SqlConnection(YAF.Classes.Config.ConnectionString);
        cn.Open();

      //  SqlCommand cmd = new SqlCommand("social_discussions_get", cn);
     //   cmd.CommandType = CommandType.StoredProcedure;

        SqlDataAdapter adap = new SqlDataAdapter("social_discussions_get", cn);
        adap.SelectCommand.CommandType = CommandType.StoredProcedure;

        DataSet ds = new DataSet();
        adap.Fill(ds,"social_discussions_get");
        
        
        
       
       
       
        commentsView.DataSource = ds;

        commentsView.DataBind();
        cn.Close();
       

        if (commentsView.Rows.Count==0)
        {
            messageBox.Text = "No messages about this property yet";
          
        }
      
       
       
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (!Request.IsAuthenticated)
        {
            Label1.Text = "Please sign in to post comments";
            return;
        }
        else if (messageBox.Text != "")
        {
            SqlConnection cn = new SqlConnection(YAF.Classes.Config.ConnectionString);
            cn.Open();

            SqlCommand cmd = new SqlCommand("social_discussions_add", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("pid", this.Master.PropertyID);
            cmd.Parameters.AddWithValue("uname", HttpContext.Current.User.Identity.Name.ToString());
            cmd.Parameters.AddWithValue("message", messageBox.Text);
            cmd.ExecuteReader();
            messageBox.Text = "";
            Page.Response.Redirect(Page.Request.Url.ToString(), true);
        }
    }


    protected void commentsView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string decodedText = HttpUtility.HtmlDecode(e.Row.Cells[0].Text);
            e.Row.Cells[0].Text = decodedText;
        }


       

    }
}